#!/bin/bash
#
# Find all Apache document roots for a list of domains.
#
# By: Gary Locke
#
# To use: Add list of domains, each on a new line, to a
#         text file. Omit '*' from wildcard subdomains.
#         Then run:
#     ./script.sh /path/to/list.txt /path/to/client.conf


domain_list=$1
if [[ -z "$domain_list" ]];then
    read -e -p "Enter path to domain list: " domain_list
fi

client_conf=$2
if [[ -z "$client_conf" ]];then
    read -e -p "Enter path to virtual host config: " client_conf
fi

echo
for domain in `cat $domain_list`;do
    conf_match=`sed -rn "/Server(Name|Alias) $domain/{p;q;}" $client_conf|egrep -v ^#|awk -F'*' '{print $1}'`
    doc_root=`grep -B100 "$conf_match" $client_conf|egrep ^DocumentRoot|tail -1|awk '{print $2}'`
    printf "$domain:\n$doc_root\n\n"
done
exit
